(function(u) {
  u(CodeMirror);
})(function(u) {
  var x, g, T, w = u.Pos;
  u.cmpPos;
  function C(i) {
    return Object.prototype.toString.call(i) == "[object Array]";
  }
  function O(i, t) {
    var l = i.doc.modeOption, a = i.options.eventType;
    l === "formEvent" && (l = "formEvent");
    var f = {}, r = u.resolveMode(l).keywords;
    if (a && a.toLowerCase() == "dwevent")
      for (let e in r) {
        const d = r[e];
        d.type && d.type.indexOf("dwevent") > -1 && (f[e] = d);
      }
    else
      for (let e in r) {
        const d = r[e];
        (d.type && d.type.indexOf("formevent") > -1 || d.type == null) && (f[e] = d);
      }
    if (i.options.formEventExpressKeywords) {
      var o = i.options.formEventExpressKeywords, v = o.boArr;
      for (let e = 0; e < v.length; e++) {
        var h = v[e];
        f[h.id] = h;
      }
      var c = o.boItemArr;
      for (let e = 0; e < c.length; e++) {
        var p = c[e];
        f[p.key] = p;
      }
      var b = o.componentArr;
      for (let e = 0; e < b.length; e++) {
        var M = b[e];
        f[M.id] = M;
      }
    }
    const H = ["grid"], I = ["validateMsg", "cell"], L = ["parent"];
    var s = "";
    if (t.state.tokenBaseArr) {
      if (t.state.tokenBaseArr.length > 1) {
        var n = t.state.tokenBaseArr;
        for (let e = n.length - 2; e >= 0 && n[e] != ";"; e--)
          if (n[e].charAt(0) == "." && t.string.charAt(0) == ".") {
            s = n[e + 1];
            break;
          } else if (n[n.length - 2] == "." && e < n.length - 2 && n[e].charAt(0) == ".") {
            s = n[e + 1];
            break;
          } else if (t.string.charAt(0) != "." && n[e] == "bracket" && n[n.length - 1] == '"') {
            s = "params";
            break;
          } else if (n[e] == "this" && t.string.charAt(0) == ".") {
            s = "this";
            break;
          } else if (n[e] == "this" && n[n.length - 2] == ".") {
            s = "this";
            break;
          }
        if (s == "params")
          for (let e = n.length - 2; e >= 0; e--) {
            if (H.indexOf(n[e]) > -1) {
              s = "boTable";
              break;
            }
            if (I.indexOf(n[e]) > -1) {
              s = "boItem";
              break;
            }
            if (L.indexOf(n[e]) > -1) {
              s = "fieldorcontainer";
              break;
            }
            if (n[e] == "ui") {
              s = "isui";
              break;
            }
          }
        if (s == "isui") {
          s = "fieldorcontainer";
          for (let e = n.length - 2; e >= 0; e--)
            if (n[e] == ",") {
              s = "boTable";
              break;
            }
        }
      }
      s == "this" && t.string.charAt(0) != "." && t.state.tokenBaseArr.length > 1 && n[n.length - 2] == ".";
    }
    var N = {};
    for (var P in f) {
      var U = f[P];
      s != "" && U.parentfunction.split(",").indexOf(s) > -1 && (N[P] = U);
    }
    return N;
  }
  function q(i) {
    var t = i.doc.modeOption;
    return t === "sql" && (t = "text/x-sql"), u.resolveMode(t).identifierQuote || "`";
  }
  function y(i) {
    return typeof i == "string" ? i : i.text;
  }
  function K(i, t) {
    return C(t) && (t = { columns: t }), t.text || (t.text = i), t;
  }
  function Q(i) {
    var t = {};
    if (C(i))
      for (var l = i.length - 1; l >= 0; l--) {
        var a = i[l];
        t[y(a).toUpperCase()] = K(y(a), a);
      }
    else if (i)
      for (var f in i)
        t[f.toUpperCase()] = K(f, i[f]);
    return t;
  }
  function E(i, t) {
    var l = i.length, a = y(t).substr(0, l);
    return i.toUpperCase() === a.toUpperCase();
  }
  function m(i, t, l, a, f) {
    if (t == "." && (t = ""), t = t.replace('"', ""), l) {
      for (var r in l)
        if (l.hasOwnProperty(r)) {
          var o = l[r];
          o && (E(t, r) || E(t, o.name)) && (f == "." ? i.push(a(o.name, null, "." + o.id)) : f.charAt(0) == '"' ? i.push(a(o.name, null, '"' + o.id)) : i.push(a(o.name, null, o.id)));
        }
    }
  }
  u.registerHelper("hint", "awsformevent", function(i, t) {
    console.log("hint"), x = Q(t && t.tables);
    var l = t && t.disableKeywords;
    q(i), g = g || [], g.columns && (g = g.columns);
    var a = i.getCursor(), f = [], r = i.getTokenAt(a), o, v, h;
    if (r.string != "")
      return r.end > a.ch && (r.end = a.ch, r.string = r.string.slice(0, a.ch - r.start)), T = i.keywords ? i.keywords : O(i, r), console.log("token.string:" + r.string), console.log("token.tokenBaseArr:" + r.state.tokenBaseArr), h = r.string, o = r.start, v = r.end, m(f, h, g, function(c) {
        return { text: c, className: "CodeMirror-hint-table CodeMirror-hint-default-table" };
      }), m(
        f,
        h,
        x,
        function(c) {
          return typeof c == "object" ? c.className = "CodeMirror-hint-table" : c = { text: c, className: "CodeMirror-hint-table" }, c;
        }
      ), l || m(f, h, T, function(c, p, b) {
        return { text: c, className: "CodeMirror-hint-keyword", desc: p, key: b };
      }, r.string), { list: f, from: w(a.line, o), to: w(a.line, v) };
  });
});
